<template>
  <div class="my-tag">
    <input
      class="input"
      type="text"
      placeholder="输入标签"
      v-if="edit"
      v-model="tag"
      @blur="hiddenInput"
      @keydown.enter="hiddenInput"
      v-focus
    />
    <div class="text" v-else @dblclick="showInput">
      {{ value }}
    </div>
  </div>
</template>

<script>
export default {
  name: 'HmMain',
  components: {},
  props: {
    value: {
      type: [String, Number],
      required: true,
    },
  },
  data() {
    return {
      edit: false,
      tag: '',
    }
  },
  methods: {
    showInput() {
      this.edit = true
      this.tag = this.value
    },
    hiddenInput() {
      this.edit = false
      this.$emit('input', this.tag)
    },
  },
}
</script>

<style scoped></style>
